package com.example.lucky.draw.server.controller;

import com.example.lucky.draw.server.common.annotation.OperationLog;
import com.example.lucky.draw.server.common.result.JsonResult;
import com.example.lucky.draw.server.protocol.po.Rule;
import com.example.lucky.draw.server.protocol.query.RuleQuery;
import com.example.lucky.draw.server.service.IRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class RuleController {

    @Autowired
    private IRuleService ruleService;

    @PostMapping("/draw/rule/findAll")
    public JsonResult<List<Rule>> findAll(@RequestBody RuleQuery ruleQuery) {
        List<Rule> rules = ruleService.findAll(ruleQuery);
        return JsonResult.ok(rules);
    }
    @OperationLog(operation = "新增抽奖规则")
    @PostMapping("/draw/rule/save")
    public JsonResult save(@RequestBody Rule rule) {
        ruleService.save(rule);
        return JsonResult.ok();
    }




}
